//
//  NSMutableAttributedString+ZXAvoidCrash.m
//  MerchantBusinessClient
//
//  Created by simon on 2020/8/28.
//  Copyright © 2020 com.Chs. All rights reserved.
//

#import "NSMutableAttributedString+ZXAvoidCrash.h"
#import "ZXAvoidCrashRuntime.h"

@implementation NSMutableAttributedString (ZXAvoidCrash)

+ (void)zx_avoidCrashExchangeMethod{
    
     static dispatch_once_t onceToken;
     dispatch_once(&onceToken, ^{
         
        Class NSConcreteMutableAttributedString = NSClassFromString(@"NSConcreteMutableAttributedString");
         
         //initWithString:
         [ZXAvoidCrashRuntime exchangeInstanceMethodWithClass:NSConcreteMutableAttributedString originalSelector:@selector(initWithString:) swizzledSelector:@selector(zx_avoidCrashInitWithString:)];
     });
}


#pragma mark - initWithString:


- (instancetype)zx_avoidCrashInitWithString:(NSString *)str
{
    id object = nil;
    
    @try {
        object = [self zx_avoidCrashInitWithString:str];
    } @catch (NSException *exception) {
        NSLog(@"exception = %@",exception);
    } @finally {
        return object;
    }
}


@end

// 崩溃：Trapped uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString initWithString:: nil value'

